﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Data.DataAccessProvider;
using DTN.Core;
using DTN.Core.Common;
using DTN.Core.Utilities;
namespace com.dtn.deals
{
    public class tbl_PartnerManager : Itbl_PartnerManager
    {
        private static Itbl_PartnerManager itbl_PartnerManager = null;
        private tbl_PartnerManager()
        {
        }
        public static Itbl_PartnerManager CreateInstance()
        {
            if (itbl_PartnerManager == null)
            {
                itbl_PartnerManager = new tbl_PartnerManager();
            }
            return itbl_PartnerManager;
        }
        public int Inserttbl_Partner(tbl_Partner tbl_partner)
        {
            DataProviderBaseClass dataProvider = DataProvider.GetDataProvider(EnumDataProviderType.SqlClient, DataHelper.GetConnectionString());
            int inumOfRowEffect = 0;
            SqlParameter[] parameters = new SqlParameter[]{
																new SqlParameter("@ID", SqlDbType.Int),
																new SqlParameter("@pName", SqlDbType.NVarChar),
																new SqlParameter("@rankMem", SqlDbType.Int),
																new SqlParameter("@rankAdmin", SqlDbType.Int),
																new SqlParameter("@Info", SqlDbType.NVarChar),
																new SqlParameter("@cityId", SqlDbType.Int),
                                                                new SqlParameter("@provinceId", SqlDbType.Int),
                                                                new SqlParameter("@AreaId", SqlDbType.VarChar),
																new SqlParameter("@contact", SqlDbType.NVarChar),
																new SqlParameter("@isDel", SqlDbType.TinyInt),
																new SqlParameter("@cDate", SqlDbType.DateTime),
                                                                new SqlParameter("@logo", SqlDbType.VarChar),
                                                                new SqlParameter("@loginName", SqlDbType.VarChar),
                                                                new SqlParameter("@pass", SqlDbType.VarChar),
                                                                new SqlParameter("@CateId", SqlDbType.Int),
                                                                new SqlParameter("@Phone",SqlDbType.NVarChar),
                                                                new SqlParameter("@Gmap",SqlDbType.NVarChar),
															};
            parameters[0].Direction = ParameterDirection.Output;
            parameters[1].Value = tbl_partner.pName;
            parameters[2].Value = tbl_partner.rankMem;
            parameters[3].Value = tbl_partner.rankAdmin;
            parameters[4].Value = tbl_partner.Info;
            parameters[5].Value = tbl_partner.cityId;
            parameters[6].Value = tbl_partner.Province;
            parameters[7].Value = tbl_partner.Area;
            parameters[8].Value = tbl_partner.contact;
            parameters[9].Value = tbl_partner.isDel;
            parameters[10].Value = tbl_partner.cDate;
            parameters[11].Value = tbl_partner.Logo;
            parameters[12].Value = tbl_partner.LoginName;
            parameters[13].Value = tbl_partner.Pass;
            parameters[14].Value = tbl_partner.CateId;
            parameters[15].Value = tbl_partner.Phone;
            parameters[16].Value = tbl_partner.ImageGMap;
            try
            {
                inumOfRowEffect = dataProvider.ExecuteNonQuery("sp_Inserttbl_Partner", CommandType.StoredProcedure, parameters);
                tbl_partner.ID = Convert.ToInt32(parameters[0].Value);
            }
            catch (Exception ex)
            {
                tbl_partner.ID = -1;
            }
            return tbl_partner.ID;
        }
        public bool Updatetbl_Partner(tbl_Partner tbl_partner)
        {
            bool bresult = false;
            DataProviderBaseClass dataProvider = DataProvider.GetDataProvider(EnumDataProviderType.SqlClient, DataHelper.GetConnectionString());
            int inumOfRowEffect = 0;
            SqlParameter[] parameters = new SqlParameter[]{
																new SqlParameter("@ID", SqlDbType.Int),
																new SqlParameter("@pName", SqlDbType.NVarChar),
																new SqlParameter("@rankMem", SqlDbType.Int),
																new SqlParameter("@rankAdmin", SqlDbType.Int),
																new SqlParameter("@Info", SqlDbType.NVarChar),
																new SqlParameter("@cityId", SqlDbType.Int),
                                                                 new SqlParameter("@provinceId", SqlDbType.Int),
                                                                new SqlParameter("@AreaId", SqlDbType.VarChar),
																new SqlParameter("@contact", SqlDbType.NVarChar),
																new SqlParameter("@isDel", SqlDbType.TinyInt),
																new SqlParameter("@cDate", SqlDbType.DateTime),
                                                                new SqlParameter("@logo", SqlDbType.VarChar),
                                                                //new SqlParameter("@loginName", SqlDbType.VarChar),
                                                                //new SqlParameter("@pass", SqlDbType.VarChar),
                                                                new SqlParameter("@CateId", SqlDbType.Int),
                                                                new SqlParameter("@Phone", SqlDbType.NVarChar),
                                                                 new SqlParameter("@GMap", SqlDbType.VarChar),
															};
            parameters[0].Value = tbl_partner.ID;
            parameters[1].Value = tbl_partner.pName;
            parameters[2].Value = tbl_partner.rankMem;
            parameters[3].Value = tbl_partner.rankAdmin;
            parameters[4].Value = tbl_partner.Info;
            parameters[5].Value = tbl_partner.cityId;
            parameters[6].Value = tbl_partner.Province;
            parameters[7].Value = tbl_partner.Area;
            parameters[8].Value = tbl_partner.contact;
            parameters[9].Value = tbl_partner.isDel;
            parameters[10].Value = tbl_partner.cDate;
            parameters[11].Value = tbl_partner.Logo;
            //parameters[12].Value = tbl_partner.LoginName;
            //parameters[13].Value = tbl_partner.Pass;
            parameters[12].Value = tbl_partner.CateId;
            parameters[13].Value = tbl_partner.Phone;
            parameters[14].Value = tbl_partner.ImageGMap;
            try
            {
                inumOfRowEffect = dataProvider.ExecuteNonQuery("sp_Updatetbl_Partner", CommandType.StoredProcedure, parameters);
                bresult = true;
            }
            catch (Exception ex)
            {
                bresult = false;
            }
            return bresult;
        }
        public bool Deletetbl_Partner(int id)
        {
            bool bresult = false;
            DataProviderBaseClass dataProvider = DataProvider.GetDataProvider(EnumDataProviderType.SqlClient, DataHelper.GetConnectionString());
            int inumOfRowEffect = 0;
            SqlParameter[] parameters = new SqlParameter[]{
																new SqlParameter("@ID", SqlDbType.Int),
															};
            parameters[0].Value = id;
            try
            {
                inumOfRowEffect = dataProvider.ExecuteNonQuery("sp_Deletetbl_Partner", CommandType.StoredProcedure, parameters);
                bresult = true;
            }
            catch (Exception ex)
            {
                bresult = false;
            }
            return bresult;
        }
        public tbl_Partner Selecttbl_PartnerByID(int id)
        {
            IDataReader dr;
            tbl_Partner tbl_partner = new tbl_Partner();
            DataProviderBaseClass dataProvider = DataProvider.GetDataProvider(EnumDataProviderType.SqlClient, DataHelper.GetConnectionString());
            SqlParameter[] parameters = new SqlParameter[]{
																new SqlParameter("@ID", SqlDbType.Int),
															};
            parameters[0].Value = id;
            try
            {
                dr = dataProvider.ExecuteReader("sp_Selecttbl_Partner", CommandType.StoredProcedure, parameters);
                while (dr.Read())
                {
                    tbl_partner.ID = Convert.ToInt32(dr["ID"].ToString());
                    tbl_partner.pName = (dr["pName"].ToString());
                    tbl_partner.rankMem = Convert.ToInt32(dr["rankMem"].ToString());
                    tbl_partner.rankAdmin = Convert.ToInt32(dr["rankAdmin"].ToString());
                    tbl_partner.Info = (dr["Info"].ToString());
                    tbl_partner.cityId = Convert.ToInt32(dr["cityId"].ToString());
                    tbl_partner.contact = (dr["contact"].ToString());
                    tbl_partner.isDel = Convert.ToInt32(dr["isDel"].ToString());
                    tbl_partner.cDate = Convert.ToDateTime(dr["cDate"].ToString());
                    tbl_partner.Logo = dr["logo"].ToString();
                    tbl_partner.LoginName = dr["loginName"].ToString();
                    tbl_partner.Pass = dr["pass"].ToString();
                    tbl_partner.Province = int.Parse(dr["provinceId"].ToString());
                    tbl_partner.Area = dr["AreaId"].ToString();
                    tbl_partner.CateId = int.Parse(dr["CateId"].ToString());
                    tbl_partner.path = dr["path"].ToString();
                    tbl_partner.Phone = dr["phone"].ToString();
                    tbl_partner.ImageGMap = dr["ImageGMap"].ToString();
                    tbl_partner.Phone = dr["Phone"].ToString();
                }

            }
            catch (Exception ex)
            {
                return null;
            }
            return tbl_partner;
        }
        public DataTable Selecttbl_PartnersDynamic(string Where, string Order)
        {
            DataSet ds = new DataSet();
            DataProviderBaseClass dataProvider = DataProvider.GetDataProvider(EnumDataProviderType.SqlClient, DataHelper.GetConnectionString());
            SqlParameter[] parameters = new SqlParameter[]{
																new SqlParameter("@WhereCondition", SqlDbType.NVarChar,500),
																new SqlParameter("@OrderByExpression", SqlDbType.NVarChar,250),
															};
            parameters[0].Value = Where;
            parameters[1].Value = Order;
            try
            {
                ds = dataProvider.ExecuteDataSet("sp_Selecttbl_PartnersDynamic", CommandType.StoredProcedure, parameters);
            }
            catch (Exception ex)
            {
                return null;
            }
            return ds.Tables["Table"];
        }
        public DataTable Selecttbl_PartnersDynamicWithPage(int StartIndex, int MaxRecords, string Where)
        {
            DataSet ds = new DataSet();
            DataProviderBaseClass dataProvider = DataProvider.GetDataProvider(EnumDataProviderType.SqlClient, DataHelper.GetConnectionString());
            SqlParameter[] parrams = { new SqlParameter("@Startindex",SqlDbType.Int ){Value = StartIndex },
                                         new SqlParameter("@Maxrecords",SqlDbType.Int ){Value = MaxRecords  },
                                         new SqlParameter("@WhereCondition",SqlDbType.NVarChar,500 ){Value = Where  }
                                     };
            try
            {
                ds = dataProvider.ExecuteDataSet("sp_Selecttbl_PartnerWithPagesDynamic", CommandType.StoredProcedure, parrams);
            }
            catch (Exception ex)
            {
                return null;
            }
            return ds.Tables["Table"];
        }
        //Cuong Code
        public static DataTable GetAndPagingByCategoryAndCity(int city, int category, int _pageSize,
                                                   int _currentPage, out int _totalRecord)
        {
            DataTable retVal = null;
            SqlConnection dbConn = new SqlConnection(AppEnv.ConnectionString);

            SqlCommand dbCmd = new SqlCommand("tbl_Partner_GetAndPagingByStatus", dbConn);
            dbCmd.Parameters.AddWithValue("@PageSize", _pageSize);
            dbCmd.Parameters.AddWithValue("@PageIndex", _currentPage);
            dbCmd.Parameters.AddWithValue("@CityId", city);
            dbCmd.Parameters.AddWithValue("@CategoryId", category);
            dbCmd.Parameters.Add(new SqlParameter("@Count", SqlDbType.Int));
            dbCmd.Parameters["@Count"].Direction = ParameterDirection.Output;
            dbCmd.CommandType = CommandType.StoredProcedure;
            try
            {
                retVal = new DataTable();
                SqlDataAdapter da = new SqlDataAdapter(dbCmd);
                da.Fill(retVal);

                _totalRecord = ConvertUtility.ToInt32(dbCmd.Parameters["@Count"].Value);
            }
            finally
            {
                dbConn.Close();
            }
            return retVal;
        }

        public static DataTable GetAndPagingByFilterAndCate(int category, int cateparent, string filter, int _pageSize,
                                                   int _currentPage, out int _totalRecord)
        {
            DataTable retVal = null;
            SqlConnection dbConn = new SqlConnection(AppEnv.ConnectionString);

            SqlCommand dbCmd = new SqlCommand("tbl_Partner_GetAndPagingByFilter", dbConn);
            dbCmd.Parameters.AddWithValue("@PageSize", _pageSize);
            dbCmd.Parameters.AddWithValue("@PageIndex", _currentPage);
            dbCmd.Parameters.AddWithValue("@ParentCategory", cateparent);
            dbCmd.Parameters.AddWithValue("@CategoryId", category);
            dbCmd.Parameters.AddWithValue("@Filter", filter);
            dbCmd.Parameters.Add(new SqlParameter("@Count", SqlDbType.Int));
            dbCmd.Parameters["@Count"].Direction = ParameterDirection.Output;
            dbCmd.CommandType = CommandType.StoredProcedure;
            try
            {
                retVal = new DataTable();
                SqlDataAdapter da = new SqlDataAdapter(dbCmd);
                da.Fill(retVal);

                _totalRecord = ConvertUtility.ToInt32(dbCmd.Parameters["@Count"].Value);
            }
            finally
            {
                dbConn.Close();
            }
            return retVal;
        }
        public static tbl_Partner GetInfo(int iD)
        {
            tbl_Partner retVal = null;
            SqlConnection dbConn = new SqlConnection(AppEnv.ConnectionString);
            SqlCommand dbCmd = new SqlCommand("tbl_Partner_GetInfo", dbConn);
            dbCmd.CommandType = CommandType.StoredProcedure;
            dbCmd.Parameters.Add("@ID", iD);
            try
            {
                dbConn.Open();
                SqlDataReader dr = dbCmd.ExecuteReader();
                if (dr.Read()) retVal = new tbl_Partner(dr);
            }
            finally
            {
                dbConn.Close();
            }
            return retVal;
        }

        public static DataTable GetAndPagingByFilterV2(int cityId, string areaid, int category, string filter, Enumerations.GroupOrder OrderBy, int _pageSize,
                                                   int _currentPage, out int _totalRecord)
        {
            DataTable retVal = null;
            SqlConnection dbConn = new SqlConnection(AppEnv.ConnectionString);

            SqlCommand dbCmd = new SqlCommand("tblCategoryFilter_GetAndPagingByFilterV2", dbConn);
            dbCmd.Parameters.AddWithValue("@PageSize", _pageSize);
            dbCmd.Parameters.AddWithValue("@PageIndex", _currentPage);
            dbCmd.Parameters.AddWithValue("@CategoryId", category);
            dbCmd.Parameters.AddWithValue("@AreaId", areaid);
            dbCmd.Parameters.AddWithValue("@CityId", cityId);
            dbCmd.Parameters.AddWithValue("@Filter", filter);
            dbCmd.Parameters.AddWithValue("@Order", (int)OrderBy);
            dbCmd.Parameters.Add(new SqlParameter("@Count", SqlDbType.Int));
            dbCmd.Parameters["@Count"].Direction = ParameterDirection.Output;
            dbCmd.CommandType = CommandType.StoredProcedure;
            try
            {
                retVal = new DataTable();
                SqlDataAdapter da = new SqlDataAdapter(dbCmd);
                da.Fill(retVal);

                _totalRecord = ConvertUtility.ToInt32(dbCmd.Parameters["@Count"].Value);
            }
            finally
            {
                dbConn.Close();
            }
            return retVal;
        }
        public static DataTable GetRecentByTopAndAreaId(int top, string areaid, int partnerid)
        {
            DataTable retVal = null;
            SqlConnection dbConn = new SqlConnection(AppEnv.ConnectionString);

            SqlCommand dbCmd = new SqlCommand("tbl_Partner_GetRecentByTopAndAreaId", dbConn);
            dbCmd.Parameters.AddWithValue("@top", top);
            dbCmd.Parameters.AddWithValue("@AreaId", areaid);
            dbCmd.Parameters.AddWithValue("@ID", partnerid);
            dbCmd.CommandType = CommandType.StoredProcedure;
            try
            {
                retVal = new DataTable();
                SqlDataAdapter da = new SqlDataAdapter(dbCmd);
                da.Fill(retVal);
            }
            finally
            {
                dbConn.Close();
            }
            return retVal;
        }

        public static void RateServices(int id, double ratePoint)
        {
            SqlConnection dbConn = new SqlConnection(AppEnv.ConnectionString);
            SqlCommand dbCmd = new SqlCommand("tbl_Partner_RateServices", dbConn);
            dbCmd.CommandType = CommandType.StoredProcedure;
            dbCmd.Parameters.AddWithValue("@Id", id);
            dbCmd.Parameters.AddWithValue("@RatePoint", ratePoint);
            try
            {
                dbConn.Open();
                dbCmd.ExecuteNonQuery();
            }
            finally
            {
                dbConn.Close();
            }
        }
        public static void RateQuality(int id, double ratePoint)
        {
            SqlConnection dbConn = new SqlConnection(AppEnv.ConnectionString);
            SqlCommand dbCmd = new SqlCommand("tbl_Partner_RateQuality", dbConn);
            dbCmd.CommandType = CommandType.StoredProcedure;
            dbCmd.Parameters.AddWithValue("@Id", id);
            dbCmd.Parameters.AddWithValue("@RatePoint", ratePoint);
            try
            {
                dbConn.Open();
                dbCmd.ExecuteNonQuery();
            }
            finally
            {
                dbConn.Close();
            }
        }
        public static void RateLandscape(int id, double ratePoint)
        {
            SqlConnection dbConn = new SqlConnection(AppEnv.ConnectionString);
            SqlCommand dbCmd = new SqlCommand("tbl_Partner_RateLandscape", dbConn);
            dbCmd.CommandType = CommandType.StoredProcedure;
            dbCmd.Parameters.AddWithValue("@Id", id);
            dbCmd.Parameters.AddWithValue("@RatePoint", ratePoint);
            try
            {
                dbConn.Open();
                dbCmd.ExecuteNonQuery();
            }
            finally
            {
                dbConn.Close();
            }
        }
        public static void RatePrice(int id, double ratePoint)
        {
            SqlConnection dbConn = new SqlConnection(AppEnv.ConnectionString);
            SqlCommand dbCmd = new SqlCommand("tbl_Partner_RatePrice", dbConn);
            dbCmd.CommandType = CommandType.StoredProcedure;
            dbCmd.Parameters.AddWithValue("@Id", id);
            dbCmd.Parameters.AddWithValue("@RatePoint", ratePoint);
            try
            {
                dbConn.Open();
                dbCmd.ExecuteNonQuery();
            }
            finally
            {
                dbConn.Close();
            }
        }


        public bool UpdateStatusPartnerById(int pId, int status)
        {
            bool IsSuccess = false;
            SqlConnection con = new SqlConnection(DataHelper.GetConnectionString());
            try
            {
                con.Open();
                SqlCommand cmd = new SqlCommand("sp_UpdateStatusPartnerById", con);
                cmd.Parameters.AddWithValue("Id", pId);
                cmd.Parameters.AddWithValue("Status", status);
                cmd.CommandType = CommandType.StoredProcedure;

                int kq = cmd.ExecuteNonQuery();
                if (kq > 0)
                    IsSuccess = true;

            }
            catch (Exception ex)
            {
                return IsSuccess;
            }
            finally
            {
                con.Close();
            }



            return IsSuccess;
        }


        public bool UpdateAcountPartner(int id, string username, string pass)
        {
            bool IsSuccess = false;
            SqlConnection con = new SqlConnection(DataHelper.GetConnectionString());
            SqlCommand cmd = new SqlCommand("sp_UpdateAcountPartner", con);
            cmd.Parameters.AddWithValue("@Id", id);
            cmd.Parameters.AddWithValue("@UserName", username);
            cmd.Parameters.AddWithValue("@Pass", pass);
            cmd.CommandType = CommandType.StoredProcedure;
            try
            {
                con.Open();
                int kq = cmd.ExecuteNonQuery();
                if (kq > 0)
                    IsSuccess = true;

            }
            catch (Exception ex)
            {
                return IsSuccess;
            }
            finally
            {
                cmd.Dispose();
                con.Close();
            }



            return IsSuccess;
        }


        public bool IsExistedUserName(string userName , int id)
        {
            bool isSuccess = false ;
            SqlConnection con = new SqlConnection(DataHelper.GetConnectionString());
            SqlCommand cmd = new SqlCommand("sp_IsExistedUserName", con);
            cmd.Parameters.AddWithValue("@UserName", userName);
            cmd.Parameters.AddWithValue("@ID", id);
            cmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int);
            cmd.Parameters[2].Direction = ParameterDirection.ReturnValue;
            cmd.CommandType = CommandType.StoredProcedure;
            try
            {
                con.Open();
                cmd.ExecuteNonQuery();
                int kq = int.Parse(cmd.Parameters["@RETURN_VALUE"].Value.ToString());
                if (kq > 0)
                    isSuccess = true;
            }
            catch (Exception ex)
            {
                return isSuccess;
            }
            finally
            {
                cmd.Dispose();
                con.Close();
            }



            return isSuccess;

        }
        /// <summary>
        /// Thống kê danh sách người mua deal cho đối tác
        /// </summary>
        /// <author>minhdv</author>
        /// <param name="Where"></param>
        /// <param name="StartIndex"></param>
        /// <param name="MaxRecords"></param>
        /// <returns>Datatable</returns>
        public DataTable ReportUserPartner(string Where, int StartIndex, int MaxRecords) 
        {
            DataSet ds = new DataSet();
            DataProviderBaseClass dataProvider = DataProvider.GetDataProvider(EnumDataProviderType.SqlClient, DataHelper.GetConnectionString());
            SqlParameter[] parrams = { new SqlParameter("@Startindex",SqlDbType.Int ){Value = StartIndex },
                                         new SqlParameter("@Maxrecords",SqlDbType.Int ){Value = MaxRecords  },
                                         new SqlParameter("@WhereCondition",SqlDbType.NVarChar,500 ){Value = Where  }
                                     };
            try
            {
                ds = dataProvider.ExecuteDataSet("sp_ReportUser_PartnerWithPagesDynamic", CommandType.StoredProcedure, parrams);
            }
            catch (Exception ex)
            {
                return null;
            }
            return ds.Tables["Table"];
        }
        public static DataTable GetAndPagingNoFilter(int cityId,string areaid, int category, Enumerations.GroupOrder OrderBy, int _pageSize,
                                                   int _currentPage, out int _totalRecord)
        {
            DataTable retVal = null;
            SqlConnection dbConn = new SqlConnection(AppEnv.ConnectionString);

            SqlCommand dbCmd = new SqlCommand("tblCategoryFilter_GetAndPagingNoFilter", dbConn);
            dbCmd.Parameters.AddWithValue("@PageSize", _pageSize);
            dbCmd.Parameters.AddWithValue("@PageIndex", _currentPage);
            dbCmd.Parameters.AddWithValue("@CategoryId", category);
            dbCmd.Parameters.AddWithValue("@AreaId", areaid);
            dbCmd.Parameters.AddWithValue("@CityId", cityId);
            dbCmd.Parameters.AddWithValue("@Order", (int)OrderBy);
            dbCmd.Parameters.Add(new SqlParameter("@Count", SqlDbType.Int));
            dbCmd.Parameters["@Count"].Direction = ParameterDirection.Output;
            dbCmd.CommandType = CommandType.StoredProcedure;
            try
            {
                retVal = new DataTable();
                SqlDataAdapter da = new SqlDataAdapter(dbCmd);
                da.Fill(retVal);

                _totalRecord = ConvertUtility.ToInt32(dbCmd.Parameters["@Count"].Value);
            }
            finally
            {
                dbConn.Close();
            }
            return retVal;
        }

        public bool ChangePassPartner(int ID, string pass) 
        {
            DataProviderBaseClass dataProvider = DataProvider.GetDataProvider(EnumDataProviderType.SqlClient, DataHelper.GetConnectionString());
            bool ret = true;
            SqlParameter[] parameters = new SqlParameter[]{
																new SqlParameter("@ID", SqlDbType.Int),
                                                                new SqlParameter("@pass", SqlDbType.VarChar)
															};
            parameters[0].Value = ID;
            parameters[1].Value = pass;

            try
            {
                dataProvider.ExecuteNonQuery("sp_ChangePasstbl_Partner", CommandType.StoredProcedure, parameters);
            }
            catch (Exception ex)
            {
                ret = false;
            }
            return ret;
        }
        public bool Updatetbl_PartnerAutoFollowUs(int ID)
        {
            bool IsSuccess = false;
            SqlConnection con = new SqlConnection(DataHelper.GetConnectionString());
            try
            {
                con.Open();
                SqlCommand cmd = new SqlCommand("sp_Updatetbl_PartnerAuto", con);
                cmd.Parameters.AddWithValue("@ID", ID);
              //  cmd.Parameters.AddWithValue("Status", status);
                cmd.CommandType = CommandType.StoredProcedure;

                int kq = cmd.ExecuteNonQuery();
                if (kq > 0)
                    IsSuccess = true;

            }
            catch (Exception ex)
            {
                return IsSuccess;
            }
            finally
            {
                con.Close();
            }

            return IsSuccess;
        }
    }
}
